package com.ruoyi.dynamic.controller.app;

import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.PageVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.RoomQuizRecord;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomAuctionStartRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomQuizAddRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomQuizSearchRequest;
import com.ruoyi.dynamic.service.IRoomQuizRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Tag(name = "App-语聊房相关活动", description = "App-语聊房相关活动")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-quiz")
public class AppRoomQuizRecordController {
    private final IRoomQuizRecordService iRoomQuizRecordService;

    public AppRoomQuizRecordController(IRoomQuizRecordService iRoomQuizRecordService) {
        this.iRoomQuizRecordService = iRoomQuizRecordService;
    }

    @Operation(summary = "用户提问", description = "用户提问")
    @PostMapping("quizAdd")
    public BaseVO quizAdd(@RequestBody @Validated AppRoomQuizAddRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomQuizRecordService.quizAdd(userId, request);
        return Result.success();
    }

    @Operation(summary = "提问列表", description = "提问列表")
    @PostMapping("listPage")
    public PageVO<RoomQuizRecord> listPage(@RequestBody @Validated AppRoomQuizSearchRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        Pages<RoomQuizRecord> pages = iRoomQuizRecordService.listPage(request, userId);
        return Result.page(pages);
    }

    @Operation(summary = "已回答下一个", description = "已回答下一个")
    @PostMapping("changeStatus")
    public BaseVO changeStatus(@RequestBody @Validated AppRoomAuctionStartRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomQuizRecordService.changeStatus(request, userId);
        return Result.successOrFail(add);
    }

    @Operation(summary = "结束问答游戏", description = "结束问答游戏")
    @GetMapping("overGame")
    public BaseVO overGame(@Parameter(description = "房间id") Long id) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomQuizRecordService.overGame(id, userId);
        return Result.successOrFail(add);
    }

    @Operation(summary = "删除问答", description = "删除问答")
    @PostMapping("delRecord")
    public BaseVO delRecord(@RequestBody @Validated AppRoomAuctionStartRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomQuizRecordService.delRecord(request, userId);
        return Result.successOrFail(add);
    }

    @Operation(summary = "置顶问答", description = "置顶问答")
    @PostMapping("topRecord")
    public BaseVO topRecord(@RequestBody @Validated AppRoomAuctionStartRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomQuizRecordService.topRecord(request, userId);
        return Result.successOrFail(add);
    }


}
